#include "Config.h"
#include <sstream>

using namespace std;

std::string Config::config_name = "Concu_Chat.ini";

Config::Config() {

}

int Config::get_int(std::string name)
{
	ifstream ini_file;
	std::string line;
	bool found = false;
	int value = -1;

	ini_file.open(config_name.c_str());

	if (ini_file.is_open()) {
		while ( getline (ini_file, line) && (!found) ) {
			size_t pos = line.find(name);
			if(pos != string::npos) {
				found = true;
				size_t start = line.find("=");
				stringstream svalue;
				svalue << line.substr(start + 1, line.size() - start - 1 );
				svalue >> value;
			}
		}
   }
	ini_file.close();
	return value;
}

std::string Config::get_string(std::string name)
{
	ifstream ini_file;
	std::string line;
	bool found = false;
	std::string value = "";

	ini_file.open(config_name.c_str());
	if (ini_file.is_open()) {
		while ( getline (ini_file, line) && (!found) ) {
			size_t pos = line.find(name);
			if(pos != string::npos) {
				found = true;
				size_t start = line.find("=");
				value = line.substr(start + 1, line.size() - start - 1 );
			}
		}
	}
	ini_file.close();
	return value;
}

Config& Config::get_instance()
{
	static Config instance;
	return instance;
}

Config::~Config() {}

